Skip to content

#21582 [BUG][dart-dio] Bug generating inline enums with common names #21591

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Aug 14, 2025

Conversation

tomcra
Copy link
Contributor

@tomcra tomcra commented Jul 18, 2025

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    (For Windows users, please run the script in WSL)
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
  • File the PR against the correct branch: master (upcoming 7.x.0 minor release - breaking changes with fallbacks), 8.0.x (breaking changes without fallbacks)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

This pull request is a fix for #21582

fix #21582

I wasn't sure what the best convention was for creating integration tests I first created it in the test\resources\bugs folder but then after rereading the contribution guidelines created updated the petstore test in modules/openapi-generator/src/test/resources/3_0/dart/petstore-with-fake-endpoints-models-for-testing.yaml

Technical committee mentions
@jaumard @josh-burton @amondnet @sbu-WBT @kuhnroyal @agilob @ahmednfwela

@tomcra tomcra marked this pull request as ready for review July 18, 2025 23:19
@wing328
Copy link
Member

wing328 commented Jul 19, 2025

thanks for the pr. please follow step 3 to update the samples when you've time to fix https://github.com/OpenAPITools/openapi-generator/actions/runs/16381888238/job/46309975996?pr=21591

…ommon names added generated samples to commit.
@tomcra
Copy link
Contributor Author

tomcra commented Jul 20, 2025

Thanks @wing328 I have updated and it includes the generated files this time.

@@ -0,0 +1,8 @@
generatorName: dart-dio
outputDir: samples/openapi3/client/bug-samples/issue_21582
inputSpec: modules/openapi-generator/src/test/resources/bugs/issues_21582.yaml
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

given that you've added the test schemas to dart petstore fake spec file, i don't think we need this yaml config and the new test spec for this particular issue: modules/openapi-generator/src/test/resources/bugs/issues_21582.yaml

Copy link
Contributor Author

@tomcra tomcra Jul 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @wing328 , I wasn't sure what the preferred convention was. I have removed the content and the generated files and updated.

…ommon names removed bug test files that were duplicates
@tomcra
Copy link
Contributor Author

tomcra commented Aug 1, 2025

@wing328 do I need to do anything else before progressing the workflow?

@wing328
Copy link
Member

wing328 commented Aug 1, 2025

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
	modified:   samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/.openapi-generator/FILES
	modified:   samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/README.md
	modified:   samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/doc/FakeApi.md
	modified:   samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/openapi.dart
	modified:   samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/api/fake_api.dart
	modified:   samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/deserialize.dart
	modified:   samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/.openapi-generator/FILES
	modified:   samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/.openapi-generator/FILES
	modified:   samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/README.md
	modified:   samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/doc/FakeApi.md
	modified:   samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api.dart
	modified:   samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api/fake_api.dart
	modified:   samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api_client.dart

Untracked files:
  (use "git add <file>..." to include in what will be committed)
	samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/doc/ObjectThatReferencesObjectsWithDuplicateInlineEnums.md
	samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/doc/ObjectWithDuplicateInlineEnum.md
	samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/doc/ObjectWithInlineEnum.md
	samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/object_that_references_objects_with_duplicate_inline_enums.dart
	samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/object_with_duplicate_inline_enum.dart
	samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/object_with_inline_enum.dart
	samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/test/object_that_references_objects_with_duplicate_inline_enums_test.dart
	samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/test/object_with_duplicate_inline_enum_test.dart
	samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/test/object_with_inline_enum_test.dart
	samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/doc/ObjectThatReferencesObjectsWithDuplicateInlineEnums.md
	samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/doc/ObjectWithDuplicateInlineEnum.md
	samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/doc/ObjectWithInlineEnum.md
	samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/object_that_references_objects_with_duplicate_inline_enums.dart
	samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/object_with_duplicate_inline_enum.dart
	samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/object_with_inline_enum.dart
	samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/test/object_that_references_objects_with_duplicate_inline_enums_test.dart
	samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/test/object_with_duplicate_inline_enum_test.dart
	samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/test/object_with_inline_enum_test.dart

please add the new files and update the samples again

tomcra added 4 commits August 4, 2025 08:43
…ommon names. Added generated files that were missed.
…ommon names. Added generated files that were missed.
…ommon names. Added generated files that where updated as a result of changes in master.
@wing328
Copy link
Member

wing328 commented Aug 13, 2025

thanks again for the pr

i did a test with the spec provided in #21582

but got errors when running dart test

   - '_$ObjectThreeSerializer' is from 'package:openapi/src/model/object_three.dart' ('lib/src/model/object_three.dart').
  Try correcting the name to the name of an existing method, or defining a method named 'ObjectThreeBuilder'.
      final result = ObjectThreeBuilder();
                     ^^^^^^^^^^^^^^^^^^
  lib/src/model/object_two.dart:25:35: Error: 'ObjectTwoBuilder' isn't a type.
    factory ObjectTwo([void updates(ObjectTwoBuilder b)]) = _$ObjectTwo;
                                    ^^^^^^^^^^^^^^^^
  lib/src/model/object_two.dart:28:25: Error: 'ObjectTwoBuilder' isn't a type.
    static void _defaults(ObjectTwoBuilder b) => b;
                          ^^^^^^^^^^^^^^^^
  lib/src/model/object_two.dart:36:50: Error: Undefined name '_$ObjectTwo'.
    final Iterable<Type> types = const [ObjectTwo, _$ObjectTwo];
                                                   ^^^^^^^^^^^
  lib/src/model/object_two.dart:69:14: Error: 'ObjectTwoBuilder' isn't a type.
      required ObjectTwoBuilder result,
               ^^^^^^^^^^^^^^^^
  lib/src/model/object_two.dart:97:20: Error: The method 'ObjectTwoBuilder' isn't defined for the class '_$ObjectTwoSerializer'.
   - '_$ObjectTwoSerializer' is from 'package:openapi/src/model/object_two.dart' ('lib/src/model/object_two.dart').
  Try correcting the name to the name of an existing method, or defining a method named 'ObjectTwoBuilder'.
      final result = ObjectTwoBuilder();
                     ^^^^^^^^^^^^^^^^
  lib/src/model/object_two.dart:119:63: Error: Undefined name '_$objectTwoAttributeEnumSerializer'.
    static Serializer<ObjectTwoAttributeEnum> get serializer => _$objectTwoAttributeEnumSerializer;
                                                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  lib/src/model/object_two.dart:123:57: Error: Undefined name '_$objectTwoAttributeEnumValues'.
    static BuiltSet<ObjectTwoAttributeEnum> get values => _$objectTwoAttributeEnumValues;
                                                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  lib/src/model/object_two.dart:124:57: Error: Method not found: '_$objectTwoAttributeEnumValueOf'.
    static ObjectTwoAttributeEnum valueOf(String name) => _$objectTwoAttributeEnumValueOf(name);
                                                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
00:00 +0 -4: Some tests failed.

did you get similar errors locally in your machine?

command to generate the dart package for testing: java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -g dart-dio -i /tmp/dart.yaml -o /tmp/dartdio/

@tomcra
Copy link
Contributor Author

tomcra commented Aug 13, 2025

@wing328 did you run dart run build_runner build to do the code generation for the built_value library before running dart test?

@wing328
Copy link
Member

wing328 commented Aug 14, 2025

that fixes it.

i'm now able to repeat the issue and confirm the fix.

thanks for the PR

if users prefer the old way of naming the enum, we will then provide an option for fallback.

@wing328 wing328 merged commit 9cb04c1 into OpenAPITools:master Aug 14, 2025
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG][dart-dio] Bug generating inline enums with common names
2 participants